
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _babelHelperVueJsxMergeProps = _interopRequireDefault(require('@vue/babel-helper-vue-jsx-merge-props'));

const _utils = require('../utils');

const _functional = require('../utils/functional');

// Utils
const _createNamespace = (0, _utils.createNamespace)('loading');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];

function LoadingIcon(h, props) {
  if (props.type === 'spinner') {
    const Spin = [];

    for (let i = 0; i < 12; i++) {
      Spin.push(h('i'));
    }

    return Spin;
  }

  return h('svg', {
    class: bem('circular'),
    attrs: {
      viewBox: '25 25 50 50',
    },
  }, [h('circle', {
    attrs: {
      cx: '50',
      cy: '50',
      r: '20',
      fill: 'none',
    },
  })]);
}

function LoadingText(h, props, slots) {
  if (slots.default) {
    const style = props.textSize && {
      fontSize: (0, _utils.addUnit)(props.textSize),
    };
    return h('span', {
      class: bem('text'),
      style,
    }, [slots.default()]);
  }
}

function Loading(h, props, slots, ctx) {
  const { color } = props;
  const { size } = props;
  const { type } = props;
  const style = {
    color,
  };

  if (size) {
    const iconSize = (0, _utils.addUnit)(size);
    style.width = iconSize;
    style.height = iconSize;
  }

  return h('div', (0, _babelHelperVueJsxMergeProps.default)([{
    class: bem([type, {
      vertical: props.vertical,
    }]),
  }, (0, _functional.inherit)(ctx, true)]), [h('span', {
    class: bem('spinner', type),
    style,
  }, [LoadingIcon(h, props)]), LoadingText(h, props, slots)]);
}

Loading.props = {
  color: String,
  size: [Number, String],
  vertical: Boolean,
  textSize: [Number, String],
  type: {
    type: String,
    default: 'circular',
  },
};

const _default = createComponent(Loading);

exports.default = _default;
